<%-- 
  - Author: Neha Chauhan
  - Date: 25-Mar-2011
  - Copyright Notice: TRAKHEES
  - Description: form.jsp
 --%>

<%@page import="ae.pcfc.etks.online.web.util.SecurityUtils"%>
<%@ include file="/WEB-INF/view/include.jsp"%>
<%@ page import="ae.pcfc.etks.online.web.*"%>


<c:choose>
	<c:when
		test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
		<script language="Javascript" type="text/javascript"
			src='<c:url value="/resources/js/jqgrid/grid.locale-ar.js"/>'></script>
	</c:when>
	<c:otherwise>
		<script language="Javascript" type="text/javascript"
			src='<c:url value="/resources/js/jqgrid/grid.locale-en.js"/>'></script>
	</c:otherwise>
</c:choose>

<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/jquery.jqGrid.min.js"/>'></script>

<!-- jQuery Date Picker Arabic Locale -->
<c:if
	test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
	<script language="Javascript"
		src='<c:url value="/resources/js/ui/jquery.ui.datepicker-ar.js"/>'></script>
</c:if>


<script type="text/javascript">
	$()
			.ready(
					function() {

						//$( "input:submit, input:reset, input:button, input:file").button();
						
						$("#UserRoleRequest")
								.validate(
										{
											onfocusout : false,
											onkeyup : false,
											onclick : false,
											rules : {
												

											},

											showErrors : function(errorMap,
													errorList) {

												var errors = '<ul>';
												var label;
												if (errorList.length) {
													$.each(errorMap, function(
															name, value) {
														label = $(
																"label[for='"
																		+ name
																		+ "']")
																.html();
														label = value + '['
																+ label + ']';
														errors = errors
																+ '<li>'
																+ label
																+ '</li>';

													});
													errors = errors + '</ul>';
													jAlert('error', errors,
															'<spring:message code="label.errormessage" />');
												}
											}

										});
			
					});
	
	
</script>

<div id="container" dir='<spring:message code="page.dir"/>'
	align='<spring:message code="page.align"/>' >


	<form:form name="UserRoleRequest" id="UserRoleRequest" method="POST"
		modelAttribute="<%=ConstantsAdmin.USER_ROLE_REQUEST_MODEL_KEY %>">


		<spring:hasBindErrors
			name="<%=ConstantsAdmin.USER_ROLE_REQUEST_MODEL_KEY %>">
			<script type="text/javascript">
				$(document)
						.ready(
								function() {
									jAlert(
											'error',
											'<li><form:errors path="*" delimiter="<li>"/>',
											'<spring:message code="label.errormessage" />');
								});
			</script>
		</spring:hasBindErrors>
		
		<%
					if(request.getAttribute(ConstantsAdmin.SUCCESS_PARAM) != null) {
				%>
		<script type="text/javascript">
				$(document)
						.ready(
								function() {
									jAlert(
											'success','<%=request.getAttribute(ConstantsAdmin.SUCCESS_PARAM)%>',
											'');
								});
			</script>			
		<% }  %>
		<% if(session.getAttribute(ConstantsAdmin.SUCCESS_PARAM) != null && request.getParameter("refNo") != null ){ 
			request.setAttribute("refNo", SecurityUtils.decryptQueryParam(request.getParameter("refNo")));
		%>
			
				<script type="text/javascript">
				$(document)
						.ready(
								function() {
									jAlert(
											'success','<spring:message code="success.role.register.request" arguments="${requestScope.refNo}"/>',
											'<spring:message code="label.menu.update.role" />');
								});
			</script>			
	
			
		<%
			session.removeAttribute(ConstantsAdmin.SUCCESS_PARAM);
		} %>
	<div class="ui-widget_c ui-corner-all" dir='<spring:message code="page.dir"/>'
	align='<spring:message code="page.align"/>' >
	<div class="ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix"><spring:message code="label.current.roles" /></div>	

	<c:choose>
		<c:when test="${null != userCurrentRoleList && fn:length(userCurrentRoleList) gt 0}">
		<table style="width: 100%" class="t_grid-table t_fin-black-txt" style="clear:both;">
			<tr class="ui-jqgrid-labels">	
			<td>
		         <div class="ui-state-default ui-th-column ui-th-ltr"><spring:message code="label.user.serialno" /></div>
		 	</td>
		 	<td>
		       	<div class="ui-state-default ui-th-column ui-th-ltr"><spring:message code="label.user.roledescriptionen" /></div>
		 	</td>
		 	<td>
		      	<div class="ui-state-default ui-th-column ui-th-ltr"><spring:message code="label.user.roledescriptionenar" /></div>
			</td>
			</tr>	
		 <c:forEach items="${userCurrentRoleList}" var="myitem" varStatus="status">
				      <tr>
				      	<td> <c:out value="${status.index +1 }"></c:out> </td>
				      	<td><c:out value="${myitem.strCrDesc}"/> </td>   
				        <td><c:out value="${myitem.strCrDescArb}"/> </td>
				      </tr> 
				    </c:forEach>
		</table>		    	
		</c:when>
		<c:otherwise>
			<spring:message code="msg.no.role.available" />
		</c:otherwise>		
	</c:choose>
	</div>
	<div class="clear"><br></div>
	<div class="ui-widget_c ui-corner-all" dir='<spring:message code="page.dir"/>'
	align='<spring:message code="page.align"/>' >
	<div class="ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix"><spring:message code="label.menu.update.role" /></div>	

	<c:choose>
		<c:when test="${null != userRoleList && fn:length(userRoleList) gt 0}">
		<table style="width: 100%" class="t_grid-table t_fin-black-txt" style="clear:both;">
			<tr class="ui-jqgrid-labels">	
			<td>
		         <div class="ui-state-default ui-th-column ui-th-ltr"><spring:message code="label.user.serialno" /></div>
		 	</td>
		 	<td>
		       	<div class="ui-state-default ui-th-column ui-th-ltr"><spring:message code="label.user.roledescriptionen" /></div>
		 	</td>
		 	<td>
		      	<div class="ui-state-default ui-th-column ui-th-ltr"><spring:message code="label.user.roledescriptionenar" /></div>
			</td>
			<td>
		      	<div class="ui-state-default ui-th-column ui-th-ltr"><spring:message code="label.select" /></div>
			</td>
			</tr>	
		 <c:forEach items="${userRoleList}" var="myitem" varStatus="status">
				      <tr>
				      	<td> <c:out value="${status.index +1 }"></c:out> </td>
				      	<td><c:out value="${myitem.strCrDesc}"/> </td>   
				        <td><c:out value="${myitem.strCrDescArb}"/> </td>
				        <td><form:checkbox path="roleIds" value="${myitem.strCrId}"/></td>
				      </tr> 
				    </c:forEach>
		</table>		    	
		<!--<form:hidden path="Id" />
		<form:label path="strRoleENG" />
		<form:label path="strRoleARB" />
			
			-->
			
		</c:when>
		<c:otherwise>
			<spring:message code="msg.no.role.available" />
		</c:otherwise>		
	</c:choose>
	</div>
	<c:choose>
		<c:when test="${null != userRoleList  && fn:length(userRoleList) gt 0}">
		<div id="fm-submit" class="fm-req">
				<input type="submit" name="save" value="<spring:message code="label.button.save" />" class="t_btns save"/>
				<input type="reset" name="reset" value="<spring:message code="label.button.reset" />" class="t_btns reset"/>
		</div>
		</c:when>
	</c:choose>	
	</form:form>
</div>
